
package CSS::Preprocessor::Scope;

use strict;
use warnings;
use fields qw(vars_stack parent);

sub new {
    my ($class) = @_;

    my $self = fields::new($class);
    $self->{vars_stack} = [{}];
    $self->{parent} = undef;
    return $self;
}

sub create_child {
    my CSS::Preprocessor::Scope $self = shift;

    my $ret = CSS::Preprocessor::Scope->new();
    $ret->{parent} = $self;
    return $ret;
}

sub _current_vars {
    my $self = shift;

    return $self->{vars_stack}->[$#{$self->{vars_stack}}];
}

sub set_var_expr {
    my ($self, $name, $expr) = @_;

    $self->_current_vars->{$name} = $expr;
}

sub get_var_expr {
    my ($self, $name) = @_;

    return $self->_current_vars->{$name};
}

sub get_var_value {
    my ($self, $name) = @_;

    die "get_var_value is not yet implemented";
}

sub push_instance {
    push @{$_[0]->{vars_stack}}, {};
    return;
}

sub pop_instance {
    pop @{$_[0]->{vars_stack}};
    return;
}

sub get_var_names {
    return keys(%{$_[0]->_current_vars});
}

1;

